package com.muti.Service.impl;

import com.muti.Service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.channel.PublishSubscribeChannel;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.Message;

/**
 * Author:yang
 * Date:2024-03-05 21:59
 * 根据所需要发送的消息选择发送的方法
 */
public class MessageServiceImpl implements MessageService {

    @Autowired
    private DirectChannel pointToPointChannel;

    @Autowired
    private PublishSubscribeChannel publishSubscribeChannel;

    @Override
    public void sendPointToPointMessage(String payload) {
        Message<String> message = MessageBuilder.withPayload(payload).build();
        pointToPointChannel.send(message);
    }

    @Override
    public void sendPublishSubscribeMessage(String payload) {
        Message<String> message = MessageBuilder.withPayload(payload).build();
        publishSubscribeChannel.send(message);
    }
}
